//
//  HNSH_TaskCenterTopView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/5/29.
//

#import "HNSH_TaskCenterTopView.h"

@interface HNSH_TaskCenterTopView ()

/* topBgView */
@property (nonatomic, strong) UIView *topBgView;
/* desLabel */
@property (nonatomic, strong) UILabel *desLabel;
/* moneyLabel */
@property (nonatomic, strong) UILabel *moneyLabel;
/* taskLabel */
@property (nonatomic, strong) UILabel *taskLabel;

@end

@implementation HNSH_TaskCenterTopView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self configUI];
    }
    return self;
}

- (void)setModel:(HNSH_TaskCenterModel *)model {
    _model = model;
    self.moneyLabel.text = [NSString stringWithFormat:@"%.2f",[model.today_income doubleValue]];
    self.taskLabel.text = model.advert_button_text;
    CGFloat width = [self.moneyLabel.text widthForFont:self.moneyLabel.font];
    [self.desLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.topBgView.mas_centerX).offset(-(24+width)/2);
    }];
}

- (void)configUI {
    [self configTopView];
}

- (void)configTopView {
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(4, 12, kScreenWidth-32, 44)];
    bgView.backgroundColor = [UIColor colorWithHexString:@"#FFB8BB"];
    bgView.layer.cornerRadius = 22.0f;
    bgView.layer.masksToBounds = YES;
    self.topBgView = bgView;
    [self addSubview:bgView];
    
    UILabel *desLabel = [[UILabel alloc]init];
    desLabel.text = @"今日任务释放绿色能量：";
    desLabel.font = [UIFont systemFontOfSize:14];
    desLabel.textColor = [UIColor appWhiteLabelColor];
    self.desLabel = desLabel;
    [bgView addSubview:desLabel];
    
    UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"task_center_home_top_shandian"]];
    [bgView addSubview:imgV];
    
    UILabel *moneyLabel = [[UILabel alloc]init];
    moneyLabel.text = @"0";
    moneyLabel.font = [UIFont boldSystemFontOfSize:24];
    moneyLabel.textColor = [UIColor appWhiteLabelColor];
    self.moneyLabel = moneyLabel;
    [bgView addSubview:moneyLabel];
    
    CGFloat width = [moneyLabel.text widthForFont:moneyLabel.font];
    [desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(bgView.mas_centerX).offset(-(24+width)/2);
        make.height.mas_equalTo(20);
        make.centerY.equalTo(bgView.mas_centerY);
    }];
    [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(desLabel.mas_right).offset(0);
        make.centerY.equalTo(desLabel.mas_centerY);
        make.width.height.mas_equalTo(24);
    }];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgV.mas_right).offset(4);
        make.centerY.equalTo(desLabel.mas_centerY);
        make.height.mas_equalTo(33);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.text = @"完成任务领取今日绿色能量";
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    titleLabel.textColor = [UIColor appWhiteLabelColor];
    [self addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_bottom).offset(16);
        make.centerX.equalTo(self.mas_centerX);
        make.height.mas_equalTo(28);
    }];
    titleLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:titleLabel.text SelectContent:@"绿色能量" CommonFont:titleLabel.font SpeFont:titleLabel.font Color:[UIColor colorWithHexString:@"#E8FFC1"]];
    
    
    UIImageView *iconImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"task_center_home_top_icon"]];
    [self addSubview:iconImgV];
    [iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_bottom).offset(44);
        make.centerX.equalTo(self.mas_centerX);
        make.width.mas_equalTo(255);
        make.height.mas_equalTo(212);
    }];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"task_center_home_top_duihuan"] forState:UIControlStateNormal];
    [self addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_bottom).offset(186);
        make.centerX.equalTo(self.mas_centerX);
        make.width.mas_equalTo(190);
        make.height.mas_equalTo(70);
    }];
    WeakSelf(weakSelf);
    [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSLog(@"点击看视频");
        if (weakSelf.showAdVideoBlock) {
            weakSelf.showAdVideoBlock();
        }
    }];
    
    UILabel *taskLabel = [[UILabel alloc]init];
    taskLabel.text = @"看视频 0/5";
    taskLabel.font = [UIFont boldSystemFontOfSize:20];
    taskLabel.textColor = [UIColor appWhiteLabelColor];
    taskLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:taskLabel];
    self.taskLabel = taskLabel;
    taskLabel.userInteractionEnabled = NO;
    [taskLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_bottom).offset(186);
        make.centerX.equalTo(self.mas_centerX);
        make.width.mas_equalTo(190);
        make.height.mas_equalTo(52);
    }];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
